All files / src/app/collections/[id]/edit page.tsx

85.71% Statements 6/7
50% Branches 1/2
100% Functions 1/1
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                            3x 3x 3x       3x   3x   1x                    
import { getSession } from "@/lib/auth";
import { redirect } from "next/navigation";
import { getDb } from "@/lib/db";
import { requireCollectionOwnerPage } from "@/lib/collection-access";
import { AppLayout } from "@/components/layout";
import { trail } from "@/components/layout/breadcrumb-trails";
import { CollectionForm } from "@/features/collections/CollectionForm";
import { DeleteCollectionSection } from "@/features/collections/DeleteCollectionSection";
 
interface EditPageProps {
  params: Promise<{ id: string }>;
}
 
export default async function EditCollectionPage({ params }: EditPageProps) {
  const { id } = await params;
  const session = await getSession();
  Iif (!session?.user) {
    redirect("/login");
  }
 
  const db = getDb();
  // Owner-only page: edit settings and delete are collection:manage operations.
  const collection = await requireCollectionOwnerPage(db, id, session.user.id);
 
  return (
    <AppLayout breadcrumbs={trail.collectionEdit(collection)}>
      <div className="mx-auto w-full max-w-2xl">
        <h1 className="mb-6 text-2xl text-ink sm:mb-8 sm:text-3xl">Edit collection</h1>
        <CollectionForm collection={collection} mode="edit" />
        <DeleteCollectionSection collectionId={collection.id} collectionName={collection.name} />
      </div>
    </AppLayout>
  );
}